package cn.com.cabinet.manager.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cabinet.base.util.PageUtils;
import com.cabinet.easy.util.Page;

import com.cabinet.web.entity.User;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.github.miemiedev.mybatis.paginator.domain.Paginator;

import cn.com.cabinet.service.UserServiceImpl;
import cn.com.easy.dto.MessageDTO;
import cn.com.easy.dto.PageRequestParamDTO;
import cn.com.easy.utils.ResponseOutputUtils;

@Controller
@RequestMapping("/manager/user")
public class UserController {
	
	@Autowired
	private UserServiceImpl userServiceImpl;
	
	@RequestMapping()
	public String redrictUser(){
		return "/User/index";
	}

	
	@RequestMapping("/list")
	public void getUser(HttpServletRequest req, HttpServletResponse res, PageRequestParamDTO paramDto, Integer key, Integer status){
		int thispage = (paramDto.getPageNumber()-1)*10;
		List<User> commodities = userServiceImpl.getUser(thispage, paramDto.getPageSize());
		
		int totalcount = userServiceImpl.getUserCount();
		Paginator p = new Paginator(thispage, paramDto.getPageSize(), totalcount);
		PageList<User> pageObject = new PageList<>(commodities, p);
		Page<User> page = PageUtils.getPage(pageObject);
		
		ResponseOutputUtils.renderJson(res, MessageDTO.newInstance("", true, page));
	}
}
